package com.uetoken.cn.activity;

import android.content.Intent;
import android.net.Uri;
import android.support.v4.content.ContextCompat;
import android.widget.TextView;

import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.SPUtils;
import com.google.gson.Gson;
import com.uetoken.cn.R;
import com.uetoken.cn.base.BaseActivity;
import com.uetoken.cn.bean.PayResultBean;
import com.uetoken.cn.common.Constant;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author 谢杨
 * @date 2018年7月30日11:16:32
 * 支付成功界面
 */
public class PaySuccessActivity extends BaseActivity {

    @BindView(R.id.tv_activity_pay_to_merchants_title)
    TextView mTvTitle;
    @BindView(R.id.tv_activity_pay_to_merchants)
    TextView mTvMerchants;
    @BindView(R.id.tv_activity_pay_to_merchants_money)
    TextView mTvMoney;
    @BindView(R.id.tv_activity_pay_to_merchants_return)
    TextView mTvActivityPayToMerchantsReturn;

    private String merchant;
    private String json;
    private PayResultBean mPayResultBean;


    @Override
    public int getLayoutId() {
        return R.layout.activity_pay_success;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this);
        BarUtils.setStatusBarColor(this, ContextCompat.getColor(this, R.color.color_app_theme), true);
    }

    @Override
    public void initData() {
        mTvTitle.setText(getResources().getString(R.string.str_pay_success));
        Intent intent = getIntent();
        json = intent.getStringExtra("json");
        mPayResultBean = new Gson().fromJson(json, PayResultBean.class);
        merchant = intent.getStringExtra("merchant");
        mTvMerchants.setText(intent.getStringExtra("subject"));
        mTvMoney.setText(intent.getStringExtra("amount"));
    }

    @Override
    public void init() {

    }

    @OnClick(R.id.tv_activity_pay_to_merchants_return)
    public void onViewClicked() {
        if (merchant.equals("yougu")) {
            Intent intentToYG = new Intent();
            intentToYG.setData(Uri.parse("yougu://ue?actionType=3001&json=" + json));
            intentToYG.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intentToYG);
        } else if (merchant.contains("believe")) {
            //{"data":{"orderno":"3938","ordernoue":"1843"},"result":1,"message":"成功"}
            PayResultBean.DataBean mPayResultDataBean = mPayResultBean.getData();
            String orderno = mPayResultDataBean.getOrderno();
            String ordernoue = mPayResultDataBean.getOrdernoue();
            int result = mPayResultBean.getResult();
            String message = mPayResultBean.getMessage();
            Intent intentToUE = new Intent();
            intentToUE.setData(Uri.parse(merchant + "://ue?actionType=8000&orderno=" + orderno + "&ordernoue=" + ordernoue + "&result=" + result + "&message=" + message));
            startActivity(intentToUE);
        } else {
            Intent intentToPcn = new Intent();
            intentToPcn.setData(Uri.parse(merchant + "://ue?actionType=3001&json=" + json));
            intentToPcn.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intentToPcn);
        }
        finish();
    }
}
